package com.example.sqlitedemo.dao.entity;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;
import org.greenrobot.greendao.DaoException;
import com.example.sqlitedemo.greendao.DaoSession;
import com.example.sqlitedemo.greendao.FaceFeatureDao;
import com.example.sqlitedemo.greendao.ShootPhotoDao;

@Entity(nameInDb = "t_shootphoto")
public class ShootPhoto {
    //    @Transient
//    @Id(autoincrement = true)
//    //id参数类型要使用Long,不然保存后id一直为0
//    private Long id;
    @Property(nameInDb = "photo_name")
    private String photoName;
    @Property(nameInDb = "photo_path")
    private String photoPath;
    @Property(nameInDb = "face_count")
    private int faceCount;
    @Id
    @Property(nameInDb = "photo_md5")
    private String photoMd5;
    //一对多的关系,一张照片可能有多个人,所以会有多个人脸特征(一张脸一个特征)
    @ToMany(referencedJoinProperty = "faceMd5")
    List<FaceFeature> faceList;

    @Property(nameInDb = "take_time")
    private String take_time;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 1983338308)
    private transient ShootPhotoDao myDao;
    @Generated(hash = 1333027641)
    public ShootPhoto(String photoName, String photoPath, int faceCount,
            String photoMd5, String take_time) {
        this.photoName = photoName;
        this.photoPath = photoPath;
        this.faceCount = faceCount;
        this.photoMd5 = photoMd5;
        this.take_time = take_time;
    }

    @Generated(hash = 1453123431)
    public ShootPhoto() {
    }

    public String getPhotoName() {
        return this.photoName;
    }

    public void setPhotoName(String photoName) {
        this.photoName = photoName;
    }

    public String getPhotoPath() {
        return this.photoPath;
    }

    public void setPhotoPath(String photoPath) {
        this.photoPath = photoPath;
    }

    public int getFaceCount() {
        return this.faceCount;
    }

    public void setFaceCount(int faceCount) {
        this.faceCount = faceCount;
    }

    public String getPhotoMd5() {
        return this.photoMd5;
    }

    public void setPhotoMd5(String photoMd5) {
        this.photoMd5 = photoMd5;
    }

    public String getTake_time() {
        return this.take_time;
    }

    public void setTake_time(String take_time) {
        this.take_time = take_time;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 561480167)
    public List<FaceFeature> getFaceList() {
        if (faceList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            FaceFeatureDao targetDao = daoSession.getFaceFeatureDao();
            List<FaceFeature> faceListNew = targetDao
                    ._queryShootPhoto_FaceList(photoMd5);
            synchronized (this) {
                if (faceList == null) {
                    faceList = faceListNew;
                }
            }
        }
        return faceList;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1860669821)
    public synchronized void resetFaceList() {
        faceList = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1594025389)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getShootPhotoDao() : null;
    }
}